//初始化执行
$(document).ready(function() {

    // 日历
    $(".date").daterangepicker({
        singleDatePicker: false,//设置为单个的datepicker，而不是有区间的datepicker 默认false
        autoUpdateInput: false,  //自动更新input输入框内的值
        autoApply:true,  //不用点击Apply或者应用按钮就可以直接取得选中的日期
        opens:'right',//设置datepicker面板防止的位置：左边、右边或者中间
        showDropdowns: true,//当设置值为true的时候，允许年份和月份通过下拉框的形式选择 默认false
        timePicker24Hour : true,//设置小时为24小时制 默认false
        timePicker : false,//可选中时分 默认false
        locale: {
            format: "YYYY/MM/DD",  //日期格式
            separator: " - ",
            daysOfWeek: ["日","一","二","三","四","五","六"],
            monthNames: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
        },
        startDate:moment()
    }, function(start, end, label) {
        $(".date").data('daterangepicker').autoUpdateInput=true;
    });
    $(".date").val("");

    // 下拉搜索功能
    // $('.select2').select2({
    //     width:'100%',    //控制Select2容器div的宽度
    //     multiple:false,  //是否允许选择多个值
    //     delay: 2500,
    //     language : "zh-CN",// 指定语言为中文，国际化才起效
    //     openOnEnter:true,   //当用户按下回车键,Select2关闭
    // })

    loadClueTable();

    $('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
        var $navtab = e.target
        var str = $navtab.toString().split("#")[1];
        if(str && str == 'clue'){
            loadClueTable();
        }else if(str && str == 'case'){
             loadCaseTable();
        }else if(str && str == 'user'){
             loadUserTable();
        }
    });

    $("body").delegate("#showClueModal", "click", function (e) {

        var paramJson = {};
        paramJson.ralateId = $(this).attr("data_id");
        paramJson.origin = 1;
        paramJson.pageSize = 10;
        paramJson.pageNum = 1;
        $('body').find('#clueModal').modal('show');
        $("#clueTableList").pagination({
            url: "/wb/map/graph/clueUserList", paramJson: paramJson, callback: function () {
            }
        });
    });

    $("body").delegate("#showCaseModal", "click", function (e) {

        var paramJson = {};
        paramJson.ralateId = $(this).attr("data_id");
        paramJson.origin = 2;
        paramJson.pageSize = 10;
        paramJson.pageNum = 1;
        $('body').find('#caseModal').modal('show');
        $("#caseTableList").pagination({
            url: "/wb/map/graph/clueUserList", paramJson: paramJson, callback: function () {
            }
        });
    });

    $("body").delegate("#showFamilyModal", "click", function (e) {
        var paramJson = {};
        paramJson.detailId = $(this).attr("data_id");
        $('body').find('#familyModal').modal('show');
        $("#familyTableList").pagination({
            url: "/wb/map/graph/userFamilyList", paramJson: paramJson, callback: function () {
            }
        });
    });

    $("body").delegate(".go-map-js", "click", function (e) {
        var graphId = $(e.target).attr("id");
        localStorage.setItem("p_from", graphId)
        location.href = "/wb/map/graph/search?graphId=" + graphId
    });

});


//-------------------------------------------------------自定义函数------------------------------------------------------


//分页查询方法
function loadClueTable() {
    var paramJson = getParams();
    $("#clueList").pagination({
        url : "/wb/map/graph/clueList",
        paramJson : paramJson,
        callback:function(){
        }
    });
}

function loadCaseTable() {
    var paramJson = getParams();
    $("#caseList").pagination({
        url : "/wb/map/graph/caseList",
        paramJson : paramJson,
        callback:function(){
        }
    });
}

function loadUserTable() {
    var paramJson = getParams();
    $("#userList").pagination({
        url : "/wb/map/graph/userList",
        paramJson : paramJson,
        callback:function(){
        }
    });
}

//获取参数方法
function getParams() {
    var formData = {};
    formData.pageSize = 10;
    formData.pageNum = 1;
    formData.graphId = $("#graphId").val();
    return formData;
}
